package logic

import (
	"context"
	"month2/C/rpc_C/order"

	"month2/C/api_C/internal/svc"
	"month2/C/api_C/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RankGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRankGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RankGoodsLogic {
	return &RankGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RankGoodsLogic) RankGoods(req *types.RankGoodsRequest) (resp *types.Response, err error) {
	goods, err := l.svcCtx.CRpc.RankGoods(l.ctx, &order.RankGoodsRequest{GoodsType: int64(req.GoodsType)})
	if err != nil {
		return &types.Response{
			Msg:  "类别排行失败",
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "类别排行成功",
		Data: goods,
		Code: 200,
	}, nil
}
